//
//  ZXYAxisContainerView.m
//  Targeting
//
//  Created by developer on 14-6-26.
//  Copyright (c) 2014年 duostec. All rights reserved.
//

#import "ZXYAxisContainerView.h"
@interface ZXYAxisContainerView()
{
    NSString *_xLabel;
    NSString *_yLabel;
    CGPoint location;
    UILabel *titleLabel;
}

@property (nonatomic,strong)UIView *subView;
@end
@implementation ZXYAxisContainerView

-(id)initWithXLabel:(NSString *)xLabel andYLabel:(NSString *)yLable withPosition:(CGPoint)position
{
    if(self = [super init])
    {
        _xLabel = [NSString stringWithFormat:@"%@",xLabel];
        _yLabel = [NSString stringWithFormat:@"%@",yLable];
        titleLabel = [[UILabel alloc] init];
        location = position;
        self.backgroundColor = [UIColor clearColor];
    }
    return  self;
}

- (void)setContentView:(UIView *)subView
{
    self.subView = subView;
    self.frame = CGRectMake(location.x, location.y, self.subView.frame.size.width+40, self.subView.frame.size.height+60);
    
    [self addSubview:self.subView];
    self.backgroundColor = [UIColor clearColor];
}

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];

    titleLabel.frame = CGRectMake(self.frame.size.width/2-50, 5, 120, 20);
    titleLabel.font  = [UIFont boldSystemFontOfSize:15];
    [self addSubview:titleLabel];
    //[self.titleOfView drawInRect:CGRectMake(self.frame.size.width/2-50, 5, 120, 20) withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:15],NSFontAttributeName, nil]];
    [_xLabel drawInRect:CGRectMake(self.frame.size.width/2-60, self.subView.frame.size.height, 120, 20) withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:15],NSFontAttributeName, nil]];
    UILabel *currentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 20)];
    currentLabel.font = [UIFont boldSystemFontOfSize:15];
    currentLabel.text = _yLabel;
    CGSize size =  [currentLabel sizeThatFits:CGSizeMake(CGFLOAT_MAX, 20)];
    currentLabel.frame = CGRectMake(0, 0, size.width, 20);
    //currentLabel.center = CGPointMake(30, self.center.y);
    
    currentLabel.transform = CGAffineTransformMakeRotation(-M_PI_2);
    currentLabel.center = CGPointMake(15, self.subView.center.y);
    
    [self addSubview:currentLabel];
    
}

- (void)setTitleOfView:(NSString *)titleOfViews
{
    titleLabel.text = titleOfViews;
}

@end
